package fhq.hcmute.edu.vn.languages;

import java.util.Locale;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;

public class Language {
	public static String Vietnamese = "vi_VN";
	public static String English = "en_US";
	public static String DEFAULT_LANGUAGE = English;
	public static String USER_LANGUAGE = "pick_language";
	public static final String KEY_LANGUAGE = "KEY_LANGUAGE";

	public static void updateLanguageSystem(Context context) {
		SharedPreferences userLanguage = context.getSharedPreferences(
				USER_LANGUAGE, 0);
		String setLanguage = userLanguage.getString(
				KEY_LANGUAGE, DEFAULT_LANGUAGE);
		setLanguage(context, setLanguage);
	}

	public static void saveLanguage(Context context, String language) {
		SharedPreferences pickLanguageSharedPreferences =
				context.getSharedPreferences(USER_LANGUAGE, 0);
		SharedPreferences.Editor myLanguageEditor =
				pickLanguageSharedPreferences.edit();
		myLanguageEditor.putString(KEY_LANGUAGE, language);
		myLanguageEditor.commit();
	}

	private static void setLanguage(Context context, String language) {
		Locale locale = new Locale(language);
		Locale.setDefault(locale);
		Configuration config = new Configuration();
		config.locale = locale;
		context.getResources().updateConfiguration(config,
				context.getResources().getDisplayMetrics());
		context = null;
	}
}
